package main

import (
	"errors"
	"github.com/GiterLab/aliyun-sms-go-sdk/dysms"
	"github.com/astaxie/beego"
	"github.com/twinj/uuid"
)

// 生成uuid
func GetUuid() string {
	theUuid := uuid.NewV4()
	return uuid.Formatter(theUuid, uuid.FormatHex)
}
func SendAliSms(mobile, code string) error {
	tempId := "SMS_190115131"
	dysms.HTTPDebugEnable = true
	dysms.SetACLClient("LTAI4GBkZgEp1u6P4w2Tq3FP", "4IdpCDJzLqPNIiPT549Wxc3f9FaIur") // dysms.New(ACCESSID, ACCESSKEY)

	// send to one person
	respSendSms, err := dysms.SendSms(GetUuid(), mobile, "禧电", tempId, `{"code":"`+code+`"}`).DoActionWithException()
	if err != nil {
		errMsg := err.Error()
		if respSendSms != nil {
			errMsg = respSendSms.Error()
		}
		beego.Debug("send sms failed", errMsg)
		return errors.New("短信发送失败:" + errMsg)
	}
	beego.Debug("send sms succeed", respSendSms.GetRequestID())
	return nil
}
